
(function ($) {
 
    $.fn.maxlength = function(){
 
        $("textarea[maxlength]").each(function () {
            var $this = $(this).on("keydown keyup focus blur", function (event) {
                    var keyCode = event.which,
                        that = this;
                    if (keyCode === 13 || keyCode >= 33) {
                        if (that.value.length >= limit) {
                            that.value = that.value.substr(0, limit);
                            event.preventDefault();
                        }
                    }
                }),
                limit = Math.abs(parseInt($this.attr("maxlength"), 10)) || -1;
        });

    };
 
})(jQuery);